package com.spark.common.widget

import android.app.Dialog
import android.content.Context
import android.graphics.drawable.ColorDrawable
import android.support.annotation.StyleRes
import android.view.LayoutInflater
import android.widget.TextView
import com.spark.common.R
import io.reactivex.annotations.NonNull

class ConfirmAlert(@NonNull context: Context?, @StyleRes themeResId: Int) : Dialog(context, themeResId) {
    constructor(@NonNull context: Context?) : this(context, R.style.ConfirmDialogStyle)

    var tvMessage: TextView

    init {
        val rootView = LayoutInflater.from(context).inflate(R.layout.layout_confirm, null)
        setContentView(rootView)
        setCancelable(true)
        setCanceledOnTouchOutside(false)
        window.setBackgroundDrawable(ColorDrawable())
        tvMessage = rootView.findViewById(R.id.tv_confirm_msg)
        val tvIKnow = rootView.findViewById<TextView>(R.id.tv_i_know)
        tvIKnow.setOnClickListener { dismiss() }
    }

    fun show(message: String = "") {
        tvMessage.text = message
        show()
    }
}
